package com.fccommunity.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.fccommunity.base.BannerData;

import java.util.List;

/**
 * Created by Administrator on 2016/4/24 0024.
 */
public class BannerPagerAdapter extends PagerAdapter {
    private List<BannerData> urls;
    private Context mContext;
    public BannerPagerAdapter(Context context, List<BannerData> urls) {
        super();
        mContext = context;
        this.urls = urls;
    }

    public int getRealCount(){
        return urls.size();
    }

    @Override
    public int getCount() {
        return urls.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imageView = new ImageView(mContext);
        Glide.with(mContext).load(urls.get(position).imgUrl).centerCrop().into(imageView);
        container.addView(imageView);
        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return "position = "+position;
    }
}
